export interface createWork {
  imgUrl: string;
  name: string;
  desc: string;
  priority?: number;
  linkUrl?: string;
  sourceUrl?: string;
}
export interface updateWork {
  imgUrl?: string;
  name?: string;
  desc?: string;
  priority?: number;
  linkUrl?: string;
  sourceUrl?: string;
}
export interface work {
  id: string;
  imgUrl: string;
  name: string;
  priority: number;
  desc: string;
  linkUrl: string;
  sourceUrl: string;
  createTime: Date;
  updateTime: Date;
}
export const create = (data: createWork) => {
  //开始请求
  return useServerRequest<work>("/works", {
    method: "POST",
    body: {
      ...data,
    },
  });
};

export const update = (id: string, data: updateWork) => {
  //开始请求
  return useServerRequest(`/works/${id}`, {
    method: "PATCH",
    body: {
      ...data,
    },
  });
};

export const findAll = () => {
  //开始请求
  return useServerRequest<work[]>("/works", {
    method: "GET",
  });
};

export const findOneById = (id: string) => {
  return useServerRequest<work>(`/works/${id}`, {
    method: "GET",
  });
};

export const deleteWork = (id: string) => {
  //开始请求
  return useServerRequest<work[]>(`/works/${id}`, {
    method: "DELETE",
    body: {},
  });
};
